//
//  LeCubeGameObject.cpp
//  Leste
//
//  Created by 王乐 on 2022/1/28.
//

#include "LeCubeGameObject.h"

#include "LeCubeRenderer.h"
#include "LeRigidBody.h"
#include "LeCubeBehaviour.h"


LeCubeGameObject::LeCubeGameObject() {
}

LeCubeGameObject::~LeCubeGameObject() {
}

void LeCubeGameObject::Initialize() {
    strName = "MyCube";
    m_bSelectable = true;

    // Transform
    // ---------
//    m_Transform.setPosition(0.0f, 0.0f, 0.0f);

    // RigidBody
    // ---------
    b2BodyDef bodyDef;
    bodyDef.userData.pointer = reinterpret_cast<uintptr_t>(this);
    bodyDef.type = b2_staticBody;
    bodyDef.position.Set(m_Transform.m_Position.x, m_Transform.m_Position.y);
    bodyDef.angle = m_Transform.m_Rotation.z;

    b2FixtureDef fixtureDef;
    b2PolygonShape polygonshape;
    polygonshape.SetAsBox(m_Transform.m_Scale.x / 2, m_Transform.m_Scale.y / 2);
    fixtureDef.shape = &polygonshape;
    fixtureDef.density = 1.0f;
    fixtureDef.friction = 0.3f;
    fixtureDef.restitution = 0.0f;

    LeRigidBody* pRigidBody = new LeRigidBody();
    pRigidBody->initRigidBody(bodyDef, fixtureDef);

    // Behaviour
    // ---------
    LeBehaviour* pBehaviour = new LeCubeBehaviour();

    // Renderer
    // --------
    LeRenderer* pRenderer = new LeCubeRenderer();
    //for dof test
    pRenderer->initRenderer(this, "/Users/wangle/CLionProjects/Leste/res/shader/cubedof.vs",
                            "/Users/wangle/CLionProjects/Leste/res/shader/cubedof.fs");

//    pRenderer->initRenderer(this, "/Users/wangle/CLionProjects/Leste/res/shader/phong.vs",
//                            "/Users/wangle/CLionProjects/Leste/res/shader/phong.fs");

    // Initialize Components
    initComponents(pRenderer, pRigidBody, pBehaviour, nullptr);
}

void LeCubeGameObject::setParameters(const glm::vec3 &position, const glm::vec3 &rotation, const glm::vec3 &scale)
{
    m_Transform.setPosition(position.x, position.y, position.z);
    m_Transform.setRotation(rotation.x, rotation.y, rotation.z);
    m_Transform.setScale(scale.x, scale.y, scale.z);
}
